home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #9 / Amiga Plus CD - 2004 - No. 09.iso / amigaplus / tools / dev_libs / feelin040718 / demos / crazygauges.c < prev    next >
C/C++ Source or Header  |  2004-08-03  |  8KB  |  271 lines

  1. ;/*
  2.    F_Create.rexx EXE CrazyGauges 
  3.    QUIT
  4.    ________________________________________________________________________
  5.  
  6.    $VER: CrazyGauges 1.0 (2003/02/10) by Olivier LAVIALE.
  7.  
  8.    This example illustrare how to write a subclass using  a  methods  table
  9.    instead of a dispatcher, and Dynamic IDs.
  10.  
  11. */
  12.  
  13. ///Header
  14. #include <stdlib.h>
  15.  
  16. #include <intuition/intuition.h>
  17. #include <libraries/feelin.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <proto/utility.h>
  22. #include <proto/feelin.h>
  23.  
  24. struct FeelinBase                  *FeelinBase;
  25. #define UtilityBase                 FeelinBase -> Utility
  26.  
  27. struct LocalObjectData
  28. {
  29.    BYTE                             Mode;
  30.    BYTE                             Way;
  31. };
  32.  
  33. #define CrazyObject  F_NewObj(Class -> Name
  34. #define Crazy(h,min,max,val,mode)            CrazyObject,                                 \
  35.                                              FA_Horizontal,             h,                \
  36.                                              "FA_Numeric_Min",          min,              \
  37.                                              "FA_Numeric_Max",          max,              \
  38.                                              "FA_Numeric_Value",        val,              \
  39.                                              F_IDA(FA_CrazyGauge_Mode), mode,             \
  40.                                              End
  41.  
  42. enum  {  // Resolved Dynamic IDs
  43.  
  44.       FA_Numeric_Value,
  45.       FA_Numeric_Min,
  46.       FA_Numeric_Max,
  47.       FA_Gauge_Simple
  48.  
  49.       }; 
  50.  
  51. enum  {  // Class's attributes
  52.  
  53.       FA_CrazyGauge_Mode
  54.  
  55.       }; 
  56.  
  57. enum  { // Special values for FA_CrazyGauge_Mode
  58.  
  59.       FV_CrazyGauge_More,
  60.       FV_CrazyGauge_Less,
  61.       FV_CrazyGauge_TwoWays,
  62.       FV_CrazyGauge_Crazy
  63.  
  64.       }; 
  65. //+
  66.  
  67. ///Crazy_New
  68. F_METHODM(ULONG,Crazy_New,TagItem)
  69. {
  70.    struct LocalObjectData *LOD = F_LOD(Class,Obj);
  71.  
  72.    LOD -> Way  = TRUE;
  73.    LOD -> Mode = F_DynamicGTD(F_IDA(FA_CrazyGauge_Mode),FV_CrazyGauge_More,Msg);
  74.  
  75.    return F_SUPERDO();
  76. }
  77. //+
  78. ///Crazy_Setup
  79. F_METHOD(ULONG,Crazy_Setup)
  80. {
  81.    if (F_SUPERDO())
  82.    {
  83.       F_Do(Obj,FM_ModifyHandler,IDCMP_INTUITICKS,0);
  84.  
  85.       return TRUE;
  86.    }
  87.    return FALSE;
  88. }
  89. //+
  90. ///Crazy_Cleanup
  91. F_METHOD(void,Crazy_Cleanup)
  92. {
  93.    F_Do(Obj,FM_ModifyHandler,0,IDCMP_INTUITICKS);
  94.  
  95.    F_SUPERDO();
  96. }
  97. //+
  98. ///Crazy_HandleEvent
  99. F_METHODM(ULONG,Crazy_HandleEvent,FS_HandleEvent)
  100. {
  101.    struct LocalObjectData *LOD = F_LOD(Class,Obj);
  102.  
  103.    if (Msg -> FEv -> Class == IDCMP_INTUITICKS)
  104.    {
  105.       LONG val,max,min;
  106.  
  107.       F_Do(Obj,FM_Get,
  108.          F_IDR(FA_Numeric_Value),  &val,
  109.          F_IDR(FA_Numeric_Max),    &max,
  110.          F_IDR(FA_Numeric_Min),    &min, TAG_DONE);
  111.  
  112.       switch (LOD -> Mode)
  113.       {
  114.          case FV_CrazyGauge_More:
  115.          {
  116.             F_Set(Obj,F_IDR(FA_Numeric_Value),(val == max) ? min : val + 1);
  117.          }
  118.          break;
  119.  
  120.          case FV_CrazyGauge_Less:
  121.          {
  122.             F_Set(Obj,F_IDR(FA_Numeric_Value),(val == min) ? max : val - 1);
  123.          }
  124.          break;
  125.  
  126.          case FV_CrazyGauge_TwoWays:
  127.          {
  128.             if (LOD -> Way)
  129.             {
  130.                if (val == max)   LOD -> Way = FALSE;
  131.                else              F_Set(Obj,F_IDR(FA_Numeric_Value),val + 1);
  132.             }
  133.             else
  134.             {
  135.                if (val == min)   LOD -> Way = TRUE;
  136.                else              F_Set(Obj,F_IDR(FA_Numeric_Value),val - 1);
  137.             }
  138.          }
  139.          break;
  140.  
  141.          case FV_CrazyGauge_Crazy:
  142.          {
  143.             F_Set(Obj,F_IDR(FA_Numeric_Value),rand() % max);
  144.          }
  145.          break;
  146.       }
  147.    }
  148.    return 0;
  149. }
  150. //+
  151.  
  152. ///Main
  153. void main(void)
  154. {
  155.    /* Attributes of my class */
  156.  
  157.    static struct FeelinDynamicEntry Attributes[] =
  158.    {
  159.       "Mode",0, NULL
  160.    }; 
  161.  
  162.    /* Dynamic IDs from my superclasses (don't need auto resolve) */
  163.  
  164.    static struct FeelinDynamicEntry Resolve[] =
  165.    {
  166.       "FA_Numeric_Value",  0,
  167.       "FA_Numeric_Min",    0,
  168.       "FA_Numeric_Max",    0,
  169.       "FA_Gauge_Simple",   0, NULL
  170.    }; 
  171.  
  172.    /* Methods handled by my class */
  173.  
  174.    static struct TagItem MTable[] =
  175.    {
  176.       (ULONG) Crazy_New,         NULL, FM_New,
  177.       (ULONG) Crazy_Setup,       NULL, FM_Setup,
  178.       (ULONG) Crazy_Cleanup,     NULL, FM_Cleanup,
  179.       (ULONG) Crazy_HandleEvent, NULL, FM_HandleEvent,
  180.       NULL
  181.    }; 
  182.  
  183.    struct FeelinClass *Class;
  184.    FObject app,win, g,b;
  185.  
  186.    if (FeelinBase = (APTR) OpenLibrary("feelin.library",FV_VERSION))
  187.    {
  188.       if (Class = F_CreateClass(FA_Class_LODSize,       sizeof (struct LocalObjectData),
  189.                                 FA_Class_Super,         FC_Gauge,
  190.                                 FA_Class_Attributes,    Attributes,
  191.                                 FA_Class_MethodsTable,  MTable,
  192.                                 FA_Class_ResolveTable,  Resolve,
  193.                                 TAG_DONE))
  194.       {
  195.          app = AppObject,
  196.             FA_Application_Title,        "demo_CrazyGauges",
  197.             FA_Application_Version,      "$VER: CrazyGauges 1.00 (2003/02/10)",
  198.             FA_Application_Copyright,    "© 2000-2003 - Olivier LAVIALE",
  199.             FA_Application_Author,       "Olivier LAVIALE <HaploLaMain@aol.com>",
  200.             FA_Application_Description,  "Show gauges & custom class",
  201.             FA_Application_Base,         "CRAZYGAUGES",
  202.  
  203.             FA_ColorScheme,   "c:FFDCA0,c:AA7864,,c:2A1E19",
  204.  
  205.             Child, win = WindowObject,
  206.                FA_ID,            MAKE_ID('M','A','I','N'),
  207.                FA_Window_Title,  "Feelin : Gauges",
  208.                FA_Window_Open,   TRUE,    /* Windows are only opened when the Client is launched (if not in sleep mode) */
  209.                FA_Back,          FI_Fill,
  210.  
  211.                Child, VGroup,
  212.                   Child, g = HGroup,
  213.                      Child, VGroup,
  214.                         Child, Gauge(TRUE,0,100,25),
  215.                         Child, Gauge(TRUE,0,100,50),
  216.                         Child, Gauge(TRUE,0,100,75),
  217.                         Child, Gauge(TRUE,0,100,100),
  218.                         Child, Crazy(TRUE,0,100,0,FV_CrazyGauge_Crazy),
  219.                      End,
  220.  
  221.                      Child, BalanceObject, FA_ID,MAKE_ID('B','L','N','C'), "FA_Balance_QuickDraw", TRUE, End,
  222.  
  223.                      Child, VGroup, FA_SetMax,FV_SetMaxH,
  224.                         Child, Crazy(TRUE,0,100,  0,FV_CrazyGauge_TwoWays),
  225.                         Child, Crazy(TRUE,0,100,100,FV_CrazyGauge_TwoWays),
  226.                         Child, Crazy(TRUE,0,100,  0,FV_CrazyGauge_TwoWays),
  227.                         Child, Crazy(TRUE,0,100,100,FV_CrazyGauge_TwoWays),
  228.                      End,
  229.                   End,
  230.  
  231.                   Child, b = TextObject,
  232.                      FA_InputMode,        FV_InputMode_Toggle,
  233.                      FA_SetMax,           TRUE,
  234.                      FA_Inner_Left,       6,
  235.                      FA_Inner_Right,      6,
  236.                      FA_Inner_Top,        3,
  237.                      FA_Inner_Bottom,     3,
  238.                      FA_Frame,            "0:21.0,0:00.0",
  239.                      FA_Back,             "0:3,0:7",
  240.                      FA_Text,             "Toggle Gauges Look",
  241.                      FA_Text_PreParse,    "<pens style=glow>",
  242.                      FA_Text_AltPreParse, "<pens text=shine>",
  243.                      FA_Text_VCenter,     TRUE,
  244.                      End,
  245.                End,
  246.  
  247.                FA_Window_ActiveObject, b, /* This is safe here */
  248.             End,
  249.          End;
  250.  
  251.          if (app)
  252.          {
  253.             F_Do(b,FM_Notify,FA_Selected,FV_Notify_Always,g,FM_Set,4,F_IDR(FA_Gauge_Simple),FV_Notify_Value,FA_Group_Forward,TRUE);
  254.             F_Do(win,FM_Notify,FA_Window_CloseRequest,TRUE,app,FM_Application_Shutdown,0);
  255.  
  256.             F_Do(app,FM_Application_Run);
  257.  
  258.             F_DisposeObj(app);
  259.          }
  260.          else Printf("Unable to create application\n");
  261.  
  262.          F_DeleteClass(Class);
  263.       }
  264.       else Printf("Unable to create custom class\n");
  265.  
  266.       CloseLibrary(FeelinBase);
  267.    }
  268.    else Printf("Unable to open feelin.library %ld\n",FV_VERSION);
  269. }
  270. //+
  271.